package com.hs.biye.controller.admin;

import com.hs.biye.constant.MessageConstant;
import com.hs.biye.model.DTO.SalaryRequest;
import com.hs.biye.model.VO.SalaryVo;
import com.hs.biye.model.entity.Salary;
import com.hs.biye.model.reslut.Result;
import com.hs.biye.service.SalaryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/salary")
public class SalaryController {

    @Resource
    private SalaryService salaryService;

    //查询薪资信息
    @GetMapping("/salaries")
    public Result<List<SalaryVo>> getSalaries(){
        List<SalaryVo> salaries = salaryService.getSalaries();
        return Result.success(salaries);
    }


    @GetMapping("/{id}")
    public Result<SalaryVo> getSalariyById(@PathVariable Integer id){
       SalaryVo salaries = salaryService.getSalariyById(id);
       return Result.success(salaries);
    }


    //查询薪资的全部和类型
    @GetMapping("/salarTotalType")
    public Result<List<Salary>> getSalaryTotalAndType(){
        List<Salary> salaryTotalAndType = salaryService.getSalaryTotalAndType();
        return Result.success(salaryTotalAndType);
    }


    //修改薪资
    @PostMapping("/update")
    public Result<Boolean> updateSalary(@RequestBody SalaryRequest salaryRequest){
        boolean b = salaryService.updateSalary(salaryRequest);
        return Result.success(b);
    }
    //添加薪资
    @PostMapping("/add")
    public Result<Boolean> addSalary(@RequestBody SalaryRequest salaryRequest){
        boolean b = salaryService.addSalary(salaryRequest);
        return Result.success(b);
    }

    //删除薪资
    @GetMapping("/delete/{id}")
    public Result<Boolean> deleteSalary(@PathVariable Integer id){
        boolean b = salaryService.deleteSalary(id);
        String msg  = null;
        if (!b){
            msg = MessageConstant.SALARY_USED;
        }
        return Result.success(b,msg);
    }
}
